<template>
  <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" width="1000px" :visible.sync="dialog" :title="'规则配置['+ ruleName +']折扣率-递减;最大折扣价-()'">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px">
      <el-collapse v-model="activeNames" @change="handleChange" v-for="(item, index) in ruleDetailList" :key="index">
        <el-collapse-item :title="item.name" :name="index">
          <el-col :span="24" v-for="(itemRule, index) in item.ruleDetailList" :key="index">
            <el-col :span="12" class="mr20">
              <el-form-item label="规则名：">
                {{itemRule.name}}
              </el-form-item>
            </el-col>
            <el-col :span="6" class="mr20">
              <el-form-item label="折扣率：">
                <el-input v-model="itemRule.discountRate" clearable maxlength="2" type="number" placeholder="请输入折扣率"/>
              </el-form-item>
            </el-col>
            <el-col :span="2">
              <el-button type="primary" :loading="loading" @click="rateSubmit(itemRule.id,itemRule.discountRate)">确定</el-button>
            </el-col>
          </el-col>
        </el-collapse-item>
      </el-collapse>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <!-- <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button> -->
    </div>
  </el-dialog>
</template>
<script>
import {updateConfigRate} from '@/api/syCategoryRule'
import { string } from 'clipboard';
export default {
  props: {
    ruleName: {
      type:String,
      required: true
    },
    ruleDetailList: {
      type:Array,
      default: []
    }
  },
  data() {
    return {
      loading: false, 
      dialog: false,
      form: {
        uid: '',
        nickname: '',
        money: '',
        ptype: '1'
      },
      activeNames: [0],
      rules: {

      }
    }
  },
  methods: {
    handleChange(val) {
      console.log(val);
    },
    cancel() {
      console.info("------------------------------")
      this.$parent.refreshParentPage();
      this.resetForm();
      
    },
    rateSubmit(id,val){
      if (id && val) {
          this.delLoading = true
          updateConfigRate(id,{ discountRate: val }).then(res => {
          this.delLoading = false
          this.$notify({
            title: '操作成功',
            type: 'success',
            duration: 1000
          })
        }).catch(err => {
          this.delLoading = false
        })
      }else{
        return this.$message.warning('折扣率不能为空！');
      }
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields();
      
    }
  }
}
</script>

<style scoped>

</style>
